package ase.eleitweg.server;

import ase.eleitweg.common.*;
import ase.eleitweg.common.fail.*;
import ase.eleitweg.server.db.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;

import com.google.inject.Inject;

public class UserLoginController extends
		AbstractLoginController<ServerUserHandle> implements UserLoginInterface {

	private static UserLoginController instance = null;
	
	@Inject ELeitwegDAO dao;
	private  UserLoginController() {
		
	}
	
		
	/*public static UserLoginController getInstance() {
		if(instance == null) {
			instance = new UserLoginController();
		}
		return instance;
	}*/
	
	@Inject ServerUserHandle suh;
	protected ServerUserHandle getSC() throws RemoteException {
		//return new ServerUserController();
		try{
			return (ServerUserHandle) UnicastRemoteObject.exportObject(suh, 0);
		} catch(ExportException e) {
			//the object already exported
			return suh;
		}
	}

	@Override
	protected boolean isAuthorised(String username, String md5passwd, User u) {
		if (username.equalsIgnoreCase(u.getUsername())
				&& md5passwd.equals(u.getPasswdhash()))
			return true;
		return false;
	}

}
